package ServiceDataFresh

import (
	"strconv"
	"ustcLab/server/common/queueUtils"
	"ustcLab/server/dao/bean"
)

func NewDataTransfer(request *bean.TPythonData) {
	dashboard := &bean.DashBoardResponse{}
	dashboard.NServer = "MINDRAY"
	dashboard.Data = make([]*bean.TDashBoard, 6)
	//血氧
	DataPoints := request.PULS_OXIM_SAT_O2
	DataPoints = "{0:" + DataPoints + "}"
	dashboard.Data[0] = &bean.TDashBoard{
		FName:            "FSao2",
		FState:           "in",
		FDataType:        "SegmentedDataType",
		FStartTime:       0,
		FIntervalTime:    0,
		FContinuousTime:  0,
		FTotalDataNumber: 1,
		FDataPoints:      DataPoints,
	}
	//心率
	DataPoints = request.PULS_OXIM_PULS_RATE
	DataPoints = "{0:" + DataPoints + "}"
	dashboard.Data[1] = &bean.TDashBoard{
		FName:            "FHr",
		FState:           "in",
		FDataType:        "SegmentedDataType",
		FStartTime:       0,
		FIntervalTime:    0,
		FContinuousTime:  0,
		FTotalDataNumber: 1,
		FDataPoints:      DataPoints,
	}
	//血压指标峰值BLD_PERF_INDEX
	DataPoints = request.BLD_PERF_INDEX
	DataPoints = "{0:" + DataPoints + "}"
	dashboard.Data[2] = &bean.TDashBoard{
		FName:            "FBpPerf",
		FState:           "in",
		FDataType:        "SegmentedDataType",
		FStartTime:       0,
		FIntervalTime:    0,
		FContinuousTime:  0,
		FTotalDataNumber: 1,
		FDataPoints:      DataPoints,
	}
	// ECG_ELEC_POTL_II 导联电压（波形数据）
	length := 499 //数据上写500个数据点，实际只有499个数据点
	strPoints := request.WaveData[0]["ECG_ELEC_POTL_II"]
	DataPoints = strConbine(strPoints, length)
	dashboard.Data[3] = &bean.TDashBoard{
		FName:            "FElecPotl",
		FState:           "in",
		FDataType:        "SegmentedDataType",
		FStartTime:       0,
		FIntervalTime:    0,
		FContinuousTime:  0,
		FTotalDataNumber: length,
		FDataPoints:      DataPoints,
	}
	// "PULS_OXIM_PLETH" 指尖容积（波形数据）
	strlen := request.WaveData[1]["ATTR_SAMP_RATE"]
	length, _ = strconv.Atoi(strlen)
	strPoints = request.WaveData[1]["PULS_OXIM_PLETH"]
	DataPoints = strConbine(strPoints, length)
	dashboard.Data[4] = &bean.TDashBoard{
		FName:            "FPleth",
		FState:           "in",
		FDataType:        "SegmentedDataType",
		FStartTime:       0,
		FIntervalTime:    0,
		FContinuousTime:  0,
		FTotalDataNumber: length,
		FDataPoints:      DataPoints,
	}
	// IMPED_TTHOR 未知指标（波形数据)
	strlen = request.WaveData[2]["ATTR_SAMP_RATE"]
	length, _ = strconv.Atoi(strlen)
	strPoints = request.WaveData[2]["IMPED_TTHOR"]
	DataPoints = strConbine(strPoints, length)
	dashboard.Data[5] = &bean.TDashBoard{
		FName:            "FImpedTthor",
		FState:           "in",
		FDataType:        "SegmentedDataType",
		FStartTime:       0,
		FIntervalTime:    0,
		FContinuousTime:  0,
		FTotalDataNumber: length,
		FDataPoints:      DataPoints,
	}
	//得到队列
	queue := queueUtils.GetQueue()
	//入队
	queue.Push(dashboard)

}

//波形图点字符串格式转换
//func strConbine(strPoints string, length int) string {
//
//	var build strings.Builder
//	build.WriteString("{")
//	var Points []string = strings.Split(strPoints, "^")
//	for i := 0; i < length-1; i++ {
//		str := strconv.Itoa(i) + ":" + Points[i] + ","
//		build.WriteString(str)
//	}
//	str := strconv.Itoa(length-1) + ":" + Points[length-1] + "}"
//	build.WriteString(str)
//	return build.String()
//}
